import { defineStore } from 'pinia';
import { ErrorMessageMode } from '/#/axios';
import { GetOrderListParams, UpdateOrderParams } from '/@/api/shopper/model/shopOrderModel';
import { getOrderListApi, getSingleOrderApi, updateOrderApi } from '/@/api/shopper/shopOrdersApi';

export const useShopOrdersStore = defineStore({
  id: 'shop-orders',
  state: () => ({}),
  getters: {},
  actions: {
    /**
     * @description: get order list
     */
    async getOrderList(
      params: GetOrderListParams & { mode?: ErrorMessageMode },
    ): Promise<object | any> {
      try {
        const { mode, ...GetOrderListParams } = params;
        const data = await getOrderListApi(GetOrderListParams, mode);
        return data;
      } catch (error) {
        return Promise.reject(error);
      }
    },
    /**
     * @description: get single order
     */
    async getSingleOrder(params: {
      id: number | string;
      mode?: ErrorMessageMode;
    }): Promise<object | any> {
      try {
        const { mode, id } = params;
        const data = await getSingleOrderApi({ id }, mode);
        return data;
      } catch (error) {
        return Promise.reject(error);
      }
    },
    /**
     * @description: update order
     */
    async updateOrder(
      params: UpdateOrderParams & {
        mode?: ErrorMessageMode;
      },
    ): Promise<object | any> {
      try {
        const { mode, ...UpdateOrderParams } = params;
        const data = await updateOrderApi(UpdateOrderParams, mode);
        return data;
      } catch (error) {
        return Promise.reject(error);
      }
    },
  },
});
